package com.situ.mall.manager.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

//封装服务器向客户端返回的json格式数据
@Data  //相当于getter和setter的结合
@ToString
@NoArgsConstructor
public class Result {

    //操作的状态码
    private Integer code;

    //返回错误的信息
    private String msg;

    //查询的结果
    private Object data;

    //静态方法
    public static Result success(Integer code,String msg,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static Result success(Object data){
        return success(0,null,data);
    }
    public static Result success(){
        return success(0,null,null);
    }
    public static Result error(Integer code,String msg,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static Result error(Integer code,String msg){
        return error(code,msg,null);
    }
    public static Result error(String msg){
        return error(-1,msg,null);
    }
}
